package com.tceasy.gateway.service;

import base.TestEnviroment;
import com.tceasy.gateway.domain.OpenDeveloper;
import com.tceasy.gateway.domain.OpenPermission;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

/**
 * Created by makunpeng on 2017/7/10 0010.
 */
public class updateSdb extends TestEnviroment {
	Logger logger = LoggerFactory.getLogger(updateSdb.class);
	@Autowired
	DeveloperService developerService;
	@Test
	public void updateDevelop()  {
		List<OpenDeveloper> list=developerService.query("","{\"createDate\":-1}",0);

		for (OpenDeveloper openDeveloper : list){
			List<OpenPermission> permissions = openDeveloper.getPermission();

			for(OpenPermission openPermission:permissions){
				if(verifyParam(openPermission)){
					openPermission.setLimitS(10L);
					System.out.println(openPermission.toString());
					try{
						developerService.updatePermission(openDeveloper.getPartner(),openPermission.getMethod(),openPermission);
						Thread.sleep(20);
					}catch (Exception e){
						logger.info(e.getMessage());
					}
				}
			}
		}
		System.out.println("==========更新数据完毕=================");
	}

	private boolean verifyParam(OpenPermission openPermission) {
		boolean flag = false;
		long limitD = openPermission.getLimitD();
		long limitH = openPermission.getLimitH();
		long limitM = openPermission.getLimitM();
		long limitS = openPermission.getLimitS();
		if(limitD == -1L && limitH == -1L && limitM == -1L && limitS == -1L){
			 flag = true;
		}
		return  flag;
	}


}
